﻿using Dict.Config;
using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Battle.Engine.LogicModel
{
    public class BuffOfState : Buff {
        
        public override Buff Clone()
        {
            var newBuff = base.Clone() as BuffOfState;
            return newBuff;
        }
        public override void Init(TableBuff tableBuff, EngineData engineData)
        {
            base.Init(tableBuff, engineData);
        }

        public override void LoadBuff0()
        {
            
        }

        public override void UnloadBuff0()
        {
            
        }

        public override void Effect()
        {
            switch (this.factor)
            {
                case TableFactorConst.poisonDam:
                    {//毒伤=(攻击力+法术攻击值)*0.6 + 毒伤加成 - 毒免伤加成
                        FActor actor = this.buffOrigion.GetSourceActor();
                        this.val = (actor.attribute.att.value + actor.attribute.matt.value) * 0.6 + actor.attribute.poison - this.buffTargetActor.attribute.antiPoison;
                        //减5%加血减免百分比 加1%攻击
                        this.buffTargetActor.attribute.minusAddperhp -= (5 * CommonMethod.tableAttributeConvert);
                        this.buffTargetActor.attribute.att.AddRate(1 * CommonMethod.tableAttributeConvert);
                    }
                    break;
                case TableFactorConst.fireDam:
                    {//火伤=(攻击力+法术攻击值)*0.6 + 火伤加成 - 火免伤加成
                        FActor actor = this.buffOrigion.GetSourceActor();
                        this.val = (actor.attribute.att.value + actor.attribute.matt.value) * 0.6 + actor.attribute.fire - this.buffTargetActor.attribute.antiFire;
                        //减3%防御 加1%攻击
                        this.buffTargetActor.attribute.pdef.AddRate(-3 * CommonMethod.tableAttributeConvert);
                        this.buffTargetActor.attribute.mdef.AddRate(-3 * CommonMethod.tableAttributeConvert);
                        this.buffTargetActor.attribute.att.AddRate(1 * CommonMethod.tableAttributeConvert);
                    }
                    break;
                case TableFactorConst.ice:
                    {
                        this.buffTargetActor.attribute.hit += (this.args1 * CommonMethod.tableAttributeConvert);
                        this.buffTargetActor.attribute.dodge += (this.args2 * CommonMethod.tableAttributeConvert);
                    }
                    break;
            }
            this.buffTargetActor.stateManager.AddStateNumByType(this, this.factor, 1);
        }

        public override void UnEffect()
        {
            switch (this.factor)
            {
                case TableFactorConst.poisonDam:
                    this.buffTargetActor.attribute.minusAddperhp += (5 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.att.AddRate(-1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.fireDam:
                    this.buffTargetActor.attribute.pdef.AddRate(3 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.mdef.AddRate(3 * CommonMethod.tableAttributeConvert);
                    this.buffTargetActor.attribute.att.AddRate(-1 * CommonMethod.tableAttributeConvert);
                    break;
                case TableFactorConst.ice:
                    {
                        this.buffTargetActor.attribute.hit -= (this.args1 * CommonMethod.tableAttributeConvert);
                        this.buffTargetActor.attribute.dodge -= (this.args2 * CommonMethod.tableAttributeConvert);
                    }
                    break;
            }
            this.buffTargetActor.stateManager.AddStateNumByType(this, this.factor, -1);
        }

    }
}
